Conditions | 5 |
Paths | 3 |
Total Lines | 53 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** global: appSettings */ |
||
15 | ipcRenderer.on('bwa:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
||
16 | const { |
||
17 | misc, |
||
18 | lookup |
||
19 | } = appSettings; |
||
20 | var bwaFileStats; // File stats, size, last changed, etc |
||
21 | |||
22 | //console.log(filePath); |
||
23 | if (filePath === undefined || filePath == '' || filePath === null) { |
||
24 | //console.log(filePath); |
||
25 | $('#bwaFileinputloading').addClass('is-hidden'); |
||
26 | $('#bwaEntry').removeClass('is-hidden'); |
||
27 | } else { |
||
28 | |||
29 | $('#bwaFileSpanInfo').text('Loading file stats...'); |
||
30 | if (isDragDrop === true) { |
||
31 | $('#bwaEntry').addClass('is-hidden'); |
||
32 | $('#bwaFileinputloading').removeClass('is-hidden'); |
||
33 | bwaFileStats = fs.statSync(filePath); |
||
34 | bwaFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
||
35 | bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
||
36 | $('#bwaFileSpanInfo').text('Loading file contents...'); |
||
37 | bwaFileContents = fs.readFileSync(filePath); |
||
38 | } else { |
||
39 | bwaFileStats = fs.statSync(filePath[0]); |
||
40 | bwaFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
||
41 | bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
||
42 | $('#bwaFileSpanInfo').text('Loading file contents...'); |
||
43 | bwaFileContents = fs.readFileSync(filePath[0]); |
||
44 | } |
||
45 | $('#bwaFileSpanInfo').text('Getting line count...'); |
||
46 | bwaFileStats['linecount'] = bwaFileContents.toString().split('\n').length; |
||
47 | bwaFileStats['filepreview'] = bwaFileContents.toString().substring(0, 50); |
||
48 | |||
49 | //console.log(readLines(filePath[0])); |
||
50 | //console.log(bwFileStats['filepreview']); |
||
51 | |||
52 | //console.log(lineCount(bwFileContents)); |
||
53 | $('#bwaFileinputloading').addClass('is-hidden'); |
||
54 | $('#bwaFileinputconfirm').removeClass('is-hidden'); |
||
55 | |||
56 | // stats |
||
57 | $('#bwaFileTdFilename').text(bwaFileStats['filename']); |
||
58 | $('#bwaFileTdLastmodified').text(conversions.getDate(bwaFileStats['mtime'])); |
||
59 | $('#bwaFileTdLastaccessed').text(conversions.getDate(bwaFileStats['atime'])); |
||
60 | $('#bwaFileTdFilesize').text(bwaFileStats['humansize'] + ' ({0} line(s))'.format(bwaFileStats['linecount'])); |
||
61 | $('#bwaFileTdFilepreview').text(bwaFileStats['filepreview'] + '...'); |
||
62 | //$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
||
63 | //console.log('cont:'+ bwFileContents); |
||
64 | |||
65 | //console.log(bwFileStats['linecount']); |
||
66 | } |
||
67 | }); |
||
68 | |||
131 |